<%@page import="com.wx.entity.User"%>
<%@page import="com.wx.database.DatabaseDao"%>
<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8"%>
<%
	StringBuffer sb = new StringBuffer();
	Random random = new Random();
	for (int i = 0; i < 4; ++i) {
		String str = String.valueOf(random.nextInt(9));
		sb.append(str);
	}
	//out.print(sb.toString());
	session.setAttribute("checkcode", sb.toString());
%>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport"
	content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>用户注册</title>
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="css/1.css" type="text/css">
<script type="text/javascript" src="js/check.js"></script>
<script type="text/javascript">
	function check_identify() {// 判断验证码是否正确
		var identify = $("identify");
		var check_img = $("check_img");
		var img = $("img");
		var check = $
		{
			sessionScope.checkcode
		}
		;
		var btn1 = $("btn1");
		//alert(check);
		if (identify.value == "") {
			check_img.innerHTML = "<img src='images/error.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
			btn1.disabled = true;
			return false;
		} else if (identify.value == check) {
			check_img.innerHTML = "<img src='images/right.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
			btn1.removeAttribute("disabled");
			return true;
		} else {
			check_img.innerHTML = "<img src='images/error.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
			btn1.setAttribute("disabled", "disabled");
			return false;
		}
	}
</script>
</head>
<body>
	<script type="text/javascript">
		// 对浏览器的UserAgent进行正则匹配，不含有微信独有标识的则为其他浏览器
		var useragent = navigator.userAgent;
		if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') {
			// 这里警告框会阻塞当前页面继续加载
			//alert('已禁止本次访问：您必须使用微信内置浏览器访问本页面！');
			// 以下代码是用javascript强行关闭当前页面
			//var opened = window.open('about:blank', '_self');
			//opened.opener = null;
			//opened.close();
		}
	</script>
	<div class="container">
		<h3 class="text-center">基于OpenCV的车牌识别系统用户注册</h3>
		<br>
		<%
			String openid = request.getParameter("openid");
			request.getSession().setAttribute("openid", request.getParameter("openid"));
			List<Integer> list = DatabaseDao.openidQueryUid(openid);
			if (list != null && list.size() > 0) {
				List<User> listUser = DatabaseDao.uidQueryUser(list.get(0));
				out.println("<font size=\"10px\">你已注册！</font><br />");
				out.println("用户名：" + listUser.get(0).getUsername() + "<br />");
				out.println("联系方式：" + listUser.get(0).getTel() + "<br />");
			} else {
		%>
		<form role="form" class="form-horizontal"
			onsubmit="return form_is_valid()" method="post" action="login.action">
			<div class="form-group">
				<div class="col-xs-10">
					<input type="text" name="username" placeholder="用户名" id="username"
						class="form-control" required onblur="userNameBlur()">
				</div>
				<div class="col-xs-2" id="check_name"></div>
			</div>
			<div class="form-group">
				<div class="col-xs-10">
					<input type="text" name="phone" placeholder="手机号码" id="phone"
						class="form-control" required onblur="phoneBlur()">
				</div>
				<div class="col-xs-2" id="check_phone"></div>
			</div>
			<div class="form-group">
				<div class="col-xs-6">
					<input type="text" name="identify" id="identify"
						class="form-control" placeholder="验证码" onblur="check_identify()">
				</div>
				<div class="col-xs-1 checkcode" id="img">
					<img alt="验证码" id="imagecode"
						src="<%=request.getContextPath()%>/checkcode.do">
				</div>
				<div class="col-xs-offset-1" id="check_img"></div>
			</div>
			<!--
			<div class="form-group">
				<div class="col-xs-6">
					<input type="text" name="indetify_tax" id="identify_tax"
						class="form-control" placeholder="短信验证码">
				</div>
				<div class="col-xs-offset-2">
					<button id="btn1" name="send" class="btn btn-primary" onclick="showTime()" disabled="disabled">发送短信验证码</button>
				</div>
			</div>
			-->
			<div class="form-group">
				<div>
					<button class="btn btn-block btn-info" name="register"
						type="submit">注册</button>
				</div>
			</div>
		</form>
		<%
			}
			out.println("你的openid为：" + openid);
		%>
	</div>
</body>
</html>